﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Study
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public Study()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public int UniversityId { get; set; }
        public string BlockName { get; set; }
        public string StudyDisplay { get; set; }
        public string StudyName { get; set; }

        public int Insert(Study obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO Study(UniversityId,BlockName,StudyDisplay,StudyName) values( N'{0}', N'{1}', N'{2}', N'{3}')",
                                       obj.UniversityId, obj.BlockName, obj.StudyDisplay, obj.StudyName);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Study obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE Study SET UniversityId='{0}', BlockName=N'{1}', StudyDisplay=N'{2}',StudyName= N'{3}' WHERe Id='{4}'"
                                       , obj.UniversityId, obj.BlockName, obj.StudyDisplay, obj.StudyName,obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(Study obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Study Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}